/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.cezary.butler.walili.server.db.tasks;

import java.util.logging.Logger;
import org.springframework.jdbc.core.SingleColumnRowMapper;

/**
 * HSQLDB COMPAT
 *
 * @author Przemysław Bałdyga
 */
public class DoesUserExistsByLoginTask extends FetchingTask {

    private static final Logger log = Logger.getLogger(DoesUserExistsByLoginTask.class.getName());
    private String LOGIN;
    private Boolean isUser;    

    public DoesUserExistsByLoginTask(String login) {
        LOGIN = login;
    }

    @Override
    public void executeInternal() {
        isUser = getJdbcTemplate().queryForObject("SELECT EXISTS(SELECT * FROM users WHERE login LIKE ?)", new SingleColumnRowMapper<Boolean>(Boolean.class), LOGIN);        
    }

    @Override
    public Boolean $getResultsNonLocking() {
        return isUser;
    }

    @Override
    public Boolean getResults() {
        return (Boolean) super.getResults();
    }
}